<template>
	<div class="box">
		<input id="upload_image" type="file" @change="change" name="image" accept="image/gif, image/jpeg ,image/png" />
		<img :src="url" alt="">
	</div>
</template>

<script>
export default {
	data(){
		return {
			url: ''
		}
	},
	methods:{
		change(e){
			console.log(e)
			var files = e.target.files,
				file;
			if (files && files.length > 0) {
				file = files[0];

				if (file.size > 1024 * 1024 * 2) {
					alert('图片大小不能超过 2MB!');
					return false;
				}

				var URL = window.URL || window.webkitURL;
				// 通过 file 生成目标 url
				var imgURL = URL.createObjectURL(file);
				this.url = imgURL
			}

		}
	}
}
</script>
<style lang="scss" scoped>

</style>
